package phoenics.app.wx;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import com.hankcs.hanlp.HanLP;
import com.hankcs.hanlp.seg.common.Term;

public class SpeakKeyWord {
	private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SpeakKeyWord.class);
	public static List<String> takeKeyWords(String text){
		if(text==null || text.trim().length()==0){
			return null;
		}
		return HanLP.segment(text).stream().map(e->e.word).collect(Collectors.toList());
	}
	public static List<String> takeKeyWords(String text,List<String> words){
		if(text==null || text.trim().length()==0){
			return null;
		}
		if(words==null || words.size()==0){
			return null;
		}
		 List<String> keyWords=new ArrayList<>();
		 List<Term> terms=HanLP.segment(text);
			for(String word:words){
				for(Term term:terms){
					if(term.word.equals(word)){
						keyWords.add(word);
					}
				}
			}
			if(keyWords.size()==0){
				return null;
			}
			return keyWords;
		 
	}
	public static boolean hasKeyWord(String text,List<String> words){
		if(text==null || text.trim().length()==0){
			return false;
		}
		if(words==null || words.size()==0){
			return false;
		}
		List<Term> terms=HanLP.segment(text);
		for(String word:words){
			for(Term term:terms){
				if(term.word.equals(word)){
					return true;
				}
			}
		}
		return false;
	}
	public static boolean hasKeyWord(String text,String word){
		if(text==null || text.trim().length()==0){
			return false;
		}
		if(word==null || word.trim().length()==0){
			return false;
		}
		List<Term> terms=HanLP.segment(text);
		for(Term term:terms){
			if(term.word.equals(word)){
				return true;
			}
		}
		return false;
	}
}
